home *** CD-ROM | disk | FTP | other *** search
- # include "defs.h"
- # include "Types.h"
- # include "OSEvents.h"
- # include "Packages.h"
-
- static char *dpndfile; /* Name of temporary file */
- static FILE *dpndf; /* Read/write pointer to dpndfile */
-
- /*
- * generate the makefile from information previously recorded
- * in the global data structures.
- * Write the output to the file whose name is recorded in the
- * macro "MAKEFILE".
- */
- makemake (argc, argv)
- int argc; /* Number of command line arguments */
- char *argv[]; /* The command line arguments */
- {
- int i; /* Loop counter */
- int t; /* Loop counter for targets[] */
- int numt; /* Number of targets */
- FILE *out; /* Output file pointer */
- char *outname; /* Output file name */
- char *p; /* Temp pointer */
- long now; /* Timestamp in seconds */
- char timestamp[255]; /* Timestamp in ascii */
- extern char *getmacro ();
- extern char *obj ();
- extern char *prargs ();
- extern char *princs ();
-
-
- /*
- * Open the output file. Use stdout if no filename is available.
- */
- if ((outname = getmacro ("MAKEFILE")) == NULL || *outname == EOS)
- {
- smacro ("MAKEFILE", "");
- out = stdout;
- outname = "";
- }
- else
- {
- progress ("Creating output file \"%s\"…\n", outname);
- if ((out = fopen (outname, "w")) == NULL)
- {
- OSgoof ("Can't open \"%s\" for writing.\n", outname);
- exit (EXIT_EXEC);
- }
- }
-
- /*
- * Count the targets.
- */
- for (numt = 0; numt < TARGETMAX && targets[numt] != NULL; numt++)
- ;
-
-
- /*
- * Build the #include dependencies, but don't output them yet;
- * the first target must be a user-specified one. We have to do
- * this now to get the list of local include files.
- */
- makedepend ();
-
- if (*outname == EOS)
- progress ("Writing makefile…\n");
- else
- progress ("Writing makefile to \"%s\"…\n", outname);
-
- /*
- * Print out a header comment.
- */
- GetDateTime (&now);
- IUTimeString (now, true, timestamp);
- fprintf (out, "# This makefile was produced at %s ", timestamp);
- IUDateString (now, abbrevDate, timestamp);
- fprintf (out, "on %s by\n", timestamp);
- fprintf (out, "# Makemake version 1.1, by Rick Holzgrafe, 12/10/86\n\n");
-
- /*
- * Print out a macro reproducing the Makemake command line.
- */
- fprintf (out, "MAKEMAKE =");
- prlist (out, argv, argc, prargs);
- fprintf (out, "\n\n");
-
- /*
- * Print a macro listing all the targets.
- */
- fprintf (out, "TARGETS =");
- prlist (out, targets, TARGETMAX, NULL);
- fprintf (out, "\n\n");
-
- /*
- * Print a macro listing all the local include files
- * (this list was made during the call to makedepend() above).
- */
- fprintf (out, "DOT_H =");
- prlist (out, dot_h, DOTHMAX, NULL);
- fprintf (out, "\n\n");
-
- /*
- * Print a macro listing all the source files.
- */
- fprintf (out, "SRCS =");
- prlist (out, sources, SOURCEMAX, NULL);
- fprintf (out, "\n\n");
-
- /*
- * Print macros listing all the object files.
- * There is one such macro and list for each target.
- * If there is more than one target, the macro names
- * are "OBJS_" suffixed by the target name; if just one
- * target, the one macro is just "OBJS".
- */
- if (numt == 1)
- {
- fprintf (out, "OBJS =");
- prlist (out, objects[0], SOURCEMAX, NULL);
- fprintf (out, "\n\n");
- }
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- fprintf (out, "OBJS_%s =", targets[t]);
- prlist (out, objects[t], SOURCEMAX, NULL);
- fprintf (out, "\n\n");
- }
-
- /*
- * Print macros listing all the libraries.
- * There is one such macro and list for each target.
- * If there is more than one target, the macro names
- * are "LIBS_" suffixed by the target name; if just one
- * target, the one macro is just "LIBS".
- */
- if (numt == 1)
- {
- fprintf (out, "LIBS =");
- prlist (out, liblist[0], LIBMAX, NULL);
- fprintf (out, "\n\n");
- }
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- fprintf (out, "LIBS_%s =", targets[t]);
- prlist (out, liblist[t], LIBMAX, NULL);
- fprintf (out, "\n\n");
- }
-
- /*
- * Print macros listing all the resource sources.
- * There is one such macro and list for each target.
- * If there is more than one target, the macro names
- * are "RES_" suffixed by the target name; if just one
- * target, the one macro is just "RES".
- */
- if (numt == 1)
- {
- fprintf (out, "RES =");
- prlist (out, reslist[0], RESMAX, NULL);
- fprintf (out, "\n\n");
- }
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- fprintf (out, "RES_%s =", targets[t]);
- prlist (out, reslist[t], RESMAX, NULL);
- fprintf (out, "\n\n");
- }
-
- /*
- * Print macros listing all the dependencies.
- * There is one such macro and list for each target.
- * If there is more than one target, the macro names
- * are "DEPS_" suffixed by the target name; if just one
- * target, the one macro is just "DEPS".
- */
- if (numt == 1)
- {
- fprintf (out, "DEPS =");
- prlist (out, deplist[0], DEPENDMAX, NULL);
- fprintf (out, "\n\n");
- }
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- fprintf (out, "DEPS_%s =", targets[t]);
- prlist (out, deplist[t], DEPENDMAX, NULL);
- fprintf (out, "\n\n");
- }
-
- /*
- * Print a macro listing all the Asm, C, and Pascal include directories.
- */
- fprintf (out, "A_INCDIRS =");
- prlist (out, adirlist, DIRMAX, princs);
- fprintf (out, "\n\n");
- fprintf (out, "C_INCDIRS =");
- prlist (out, cdirlist, DIRMAX, princs);
- fprintf (out, "\n\n");
- fprintf (out, "P_INCDIRS =");
- prlist (out, pdirlist, DIRMAX, princs);
- fprintf (out, "\n\n");
-
- /*
- * Print out the AOptions macro.
- * AOptions gets special attention: it gets the string "{A_INCDIRS}"
- * appended.
- */
- p = getmacro ("AOptions");
- if (p == NULL)
- p = "";
- fprintf (out, "%-12s = %s",
- "AOptions", p);
- fprintf (out, " {A_INCDIRS}\n\n");
-
- /*
- * Print out the COptions macro.
- * COptions gets special attention: it gets the string "{C_INCDIRS}"
- * appended.
- */
- p = getmacro ("COptions");
- if (p == NULL)
- p = "";
- fprintf (out, "%-12s = %s",
- "COptions", p);
- fprintf (out, " {C_INCDIRS}\n\n");
-
- /*
- * Print out the POptions macro.
- * POptions gets special attention: it gets the string "{P_INCDIRS}"
- * appended.
- */
- p = getmacro ("POptions");
- if (p == NULL)
- p = "";
- fprintf (out, "%-12s = %s",
- "POptions", p);
- fprintf (out, " {P_INCDIRS}\n\n");
-
- /*
- * Print out the rest of the macros, which are not
- * lists of files. Most are just printed verbatim.
- */
- for (i = 0; i < MACROMAX && macrolist[i].mname != NULL; i++)
- {
- if (strcmp (macrolist[i].mname, "COptions") != 0)
- {
- fprintf (out, "%-12s = %s\n",
- macrolist[i].mname, macrolist[i].mvalue);
- }
- }
- fprintf (out, "\n");
-
- /*
- * Prepare to print the targets, their dependencies, and their
- * productions.
- */
- if (numt == 1)
- {
- /*
- * If there is just one target, print it out.
- */
- fprintf (out, "\n%s\tƒ", targets[0]);
- if (reslist[0][0] != NULL)
- {
- fprintf (out, " {OBJS} {LIBS} %s.r.o {DEPS}\n",
- targets[0]);
- fprintf (out, "\t{DUP} {DUPOPTS} %s.r.o {LINKTEMP}\n", targets[0]);
- }
- else
- fprintf (out, " {OBJS} {LIBS} {DEPS}\n");
- fprintf (out, "\t{LINK} {LINKOPTS} -o {LINKTEMP} {OBJS} {LIBS}\n",
- targets[0]);
- fprintf (out, "\t{RENAME} {RENAMEOPTS} {LINKTEMP} {Targ}\n");
- fprintf (out, "\t{POST} {POSTOPTS} {Targ} {POSTARGS}\n");
- }
- else
- {
- /*
- * If there are multiple targets, print first a production
- * "all" which depends on the targets, then print the
- * productions for the targets.
- */
- fprintf (out, "all\tƒ");
- for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- fprintf (out, " %s", targets[t]);
- fprintf (out, "\n\n");
- for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- fprintf (out, "\n%s\tƒ", targets[t]);
- if (reslist[0][0] != NULL)
- {
- fprintf (out, " {OBJS_%s} {LIBS_%s} %s.r.o {DEPS_%s}\n",
- targets[t], targets[t], targets[t], targets[t]);
- fprintf (out, "\t{DUP} {DUPOPTS} %s.r.o {LINKTEMP}\n",
- targets[t]);
- }
- else
- fprintf (out, " {OBJS_%s} {LIBS_%s} {DEPS_%s}\n",
- targets[t], targets[t], targets[t]);
- fprintf (out, "\t{LINK} {LINKOPTS} -o {LINKTEMP} ");
- fprintf (out, "{OBJS_%s} {LIBS_%s}\n",
- targets[t], targets[t]);
- fprintf (out, "\t{RENAME} {RENAMEOPTS} {LINKTEMP} {Targ}\n");
- fprintf (out, "\t{POST} {POSTOPTS} {Targ} {POSTARGS}\n");
- }
- }
- fprintf (out, "\n\n");
-
- /*
- * For targets with resource dependencies, output a production
- * for making the resource fork.
- */
- if (numt == 1)
- {
- if (reslist[0][0] != NULL)
- {
- fprintf (out, "%s.r.o\tƒ {RES}", targets[0]);
- for (i = 0; i < RESMAX && reslist[0][i] != NULL; i++)
- depend (out, reslist[0][i]);
- fprintf (out, "\n\t{REZ} {REZOPTS} {TARG} {RES}\n\n");
- }
- }
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- {
- if (reslist[t][0] != NULL)
- {
- fprintf (out, "%s.r.o\tƒ {RES_%s}", targets[t], targets[t]);
- for (i = 0; i < RESMAX && reslist[t][i] != NULL; i++)
- depend (out, reslist[t][i]);
- fprintf (out, "\n\t{REZ} {REZOPTS} {TARG} {RES_%s}\n\n",
- targets[t]);
- }
- }
-
- /*
- * Boilerplate for assorted small-scale useful productions
- */
- fprintf (out, "{MAKEFILE}\tƒ NoneSuchFile\n");
- fprintf (out, "NoneSuchFile\tƒ\n\t{MAKEMAKE}\n\n");
-
- fprintf (out, "clean\tƒ\n\t{DELETE} {DELETEOPTS} ");
- if (numt == 1)
- fprintf (out, " {OBJS}");
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- fprintf (out, " {OBJS_%s}", targets[t]);
- fprintf (out, "\n\n");
-
- fprintf (out, "clobber\tƒ clean\n\t{DELETE} {DELETEOPTS} {TARGETS}\n\n");
-
- fprintf (out, "count\tƒ\n\t{COUNT} {COUNTOPTS} {DOT_H} {SRCS}\n\n");
-
- fprintf (out,
- "files\tƒ\n\t{FILES} {FILESOPTS} {TARGETS} {DOT_H} {SRCS}");
- if (numt == 1)
- fprintf (out, " {OBJS}");
- else for (t = 0; t < TARGETMAX && targets[t] != NULL; t++)
- fprintf (out, " {OBJS_%s}", targets[t]);
- fprintf (out, " {MAKEFILE}\n\n");
-
- fprintf (out,
- "print\tƒ\n\t{PRINT} {PRINTOPTS} {DOT_H} {SRCS} {MAKEFILE}\n\n");
-
- fprintf (out,
- "tags\tƒ {DOT_H} {SRCS}\n\t{CTAGS} {CTAGSOPTS} {C_INCDIRS} {NewerDeps}\n\n");
-
- /*
- * Now at last we can print out the #include dependencies
- * which were generated at the top of this routine.
- */
- getdepend (out);
-
- /*
- * Close the file, and set it to type 'TEXT'.
- */
- fclose (out);
- setfile (outname);
-
- /*
- * Done!
- */
- }
-
- /*
- * Create a temporary file in which to write the list of include
- * dependencies. (We must create the list early to learn about it,
- * but output it late, so its productions come after the default ones
- * and the more interesting ones.) Then call depend() on each source
- * file to generate the list.
- */
- makedepend ()
- {
- int i;
-
- /*
- * Create a temp file for reading and writing.
- */
- dpndfile = "Makemake.temp";
- progress ("Creating temporary file \"%s\"…\n", dpndfile);
- if ((dpndf = fopen (dpndfile, "w+")) == NULL)
- {
- OSgoof ("Can't create \"%s\" for reading and writing.\n",
- dpndfile);
- exit (EXIT_EXEC);
- }
-
- /*
- * For each source file, run depend() to list its
- * #include dependencies.
- */
- for (i = 0; i < SOURCEMAX && sources[i] != NULL; i++)
- {
- depend (dpndf, sources[i]);
- fprintf (dpndf, "\n");
- }
- }
-
- /*
- * Print the temp file (which holds the list of #include dependencies)
- * to the given output, then remove the temp file.
- */
- getdepend (out)
- FILE *out;
- {
- int sz;
- char buf[BUFSIZ];
-
- rewind (dpndf);
- while ((sz = fread (buf, 1, BUFSIZ, dpndf)) != 0)
- fwrite (buf, 1, sz, out);
- fclose (dpndf);
- progress ("Removing temporary file \"%s\"…\n", dpndfile);
- unlink (dpndfile);
- }
-
- /*
- * Given a source filename, generate the corresponding object file name.
- * The object file name is returned in a re-usable buffer, and so
- * must be copied somewhere safe by the caller if the name is to be saved.
- */
- char *obj (s)
- char *s;
- {
- static char buf[LINELEN];
-
- strncpy (buf, s, LINELEN);
- buf[LINELEN - 3] = EOS;
- strcat (buf, ".o");
-
- return (buf);
- }
-
- prlist (out, list, max, prfunc)
- FILE *out;
- char *list[];
- int max;
- char *(*prfunc)();
- {
- int i;
- int len;
- int linelen = 0;
- char *p;
-
- for (i = 0; i < max && list[i] != NULL; i++)
- {
- if (prfunc != NULL)
- {
- p = prfunc (list[i]);
- len = strlen (p);
- }
- else
- {
- len = strlen (list[i]) + 1;
- p = NULL;
- }
-
- if (linelen + len > 50)
- {
- fprintf (out, " ∂\n\t");
- linelen = len;
- }
- else
- linelen += len;
-
- if (p != NULL)
- fprintf (out, "%s", p);
- else
- fprintf (out, " %s", list[i]);
- }
- }
-
- /*
- * Format the given string (in this case, prefix a space and put
- * single quotes around it) and return a pointer to it in a
- * re-usable buffer.
- */
- char *prargs (s)
- char *s;
- {
- static char buf[LINELEN];
-
- sprintf (buf, " '%s'", s);
- return (buf);
- }
-
- char *princs (s)
- char *s;
- {
- static char buf[LINELEN];
-
- sprintf (buf, " -i %s", s);
- return (buf);
- }
-